package com.wkhyapp.lm.contract;

import com.wkhyapp.lm.base.BasePresenter;
import com.wkhyapp.lm.http.ApiCallback;
import com.wkhyapp.lm.http.net.BaseRequest;
import com.wkhyapp.lm.http.net.CategorysAddRequest;
import com.wkhyapp.lm.http.net.SuperResponse;
import com.wkhyapp.lm.http.vo.Category;
import com.wkhyapp.lm.utils.MemberUtils;

/**
 * Created by fang on 2021/10/24.
 */

public class UserCategoryPresenter extends BasePresenter<UserCategoryView> {

    public UserCategoryPresenter(UserCategoryView userCategoryView) {
        super(userCategoryView);
    }

    public void getCategory(){
        BaseRequest request = new BaseRequest();
        request.setUserId(MemberUtils.getUid());
        addSubscription(apiStores.userCategorys(request),new ApiCallback<SuperResponse<Category>>() {
            @Override
            public void onSuccess(SuperResponse<Category> response) {
                mvpView.setCategory(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }


    public void addCategory(String name){
        CategorysAddRequest request = new CategorysAddRequest();
        request.setUserId(MemberUtils.getUid());
        request.setName(name);
        addSubscription(apiStores.memberCategorysAdd(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.setSucc();
            }
            @Override
            public void onFailure(String msg) {
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }

    public void updateCategory(String name,int id){
        CategorysAddRequest request = new CategorysAddRequest();
        request.setUserId(MemberUtils.getUid());
        request.setName(name);
        request.setId(id);
        addSubscription(apiStores.memberCategorysUpdate(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.setSucc();
            }
            @Override
            public void onFailure(String msg) {
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });
    }
}
